package com.anxin.controller;

import com.anxin.entity.Message;
import com.anxin.service.MessageService;
import com.anxin.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Tag(name = "消息管理")
@RestController
@RequestMapping("/api/message")
public class MessageController extends BaseController {
    @Autowired
    private MessageService messageService;

    @Operation(summary = "根据ID获取消息")
    @GetMapping("/{id}")
    public Result<Message> getById(@Parameter(description = "消息ID") @PathVariable String id) {
        return Result.success(messageService.getById(id));
    }

    @Operation(summary = "获取消息列表")
    @GetMapping("/list")
    public Result<List<Message>> list() {
        return Result.success(messageService.list());
    }

    @Operation(summary = "保存或更新消息")
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody Message message) {
        return Result.success(messageService.saveOrUpdate(message));
    }

    @Operation(summary = "删除消息")
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@Parameter(description = "消息ID") @PathVariable String id) {
        return Result.success(messageService.removeById(id));
    }
} 